package com.zsyh.jiujiu.home;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.base.BaseFragment;
import com.example.zyh.toolslib.widget.TitleBar;
import com.zsyh.jiujiu.R;
import com.zsyh.jiujiu.fragment.NewHomeFragment;
import com.zsyh.jiujiu.fragment.vipFragment.MonthFragment;
import com.zsyh.jiujiu.fragment.vipFragment.ZhuceFragment;
import com.zsyh.jiujiu.fragment.vipFragment.yearFragment;
import com.zsyh.jiujiu.weight.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: livvehelp
 * @Package: com.zsyh.lsb.ui
 * @ClassName:
 * @Description: java类作用描述
 * @Author: zsyh
 * @CreateDate: 2020/9/7 11:59
 * @UpdateUser: liangwanbo
 * @UpdateDate: 2020/9/7 11:59
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MyvipActtivitty extends BaseActivity {

    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.viewpager)
    NoScrollViewPager viewpager;
    @BindView(R.id.zuo)
    ImageView zuo;
    @BindView(R.id.you)
    ImageView you;
    private List<BaseFragment> fragmentList;
    private int selectPos = 0;
    private String[] title = new String[]{"", "", ""};
    private ZhuceFragment zhuceFragment;
    private MonthFragment monthFragment;
    private yearFragment yearFragment;
    private int index=0;

    @Override
    protected int initLayout() {
        return R.layout.activitty_vip;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        fragmentList = new ArrayList<>();
        zhuceFragment = new ZhuceFragment();
        monthFragment = new MonthFragment(this);
        yearFragment = new yearFragment(this);
        fragmentList.add(zhuceFragment);
        fragmentList.add(monthFragment);
        fragmentList.add(yearFragment);
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        viewpager.setOffscreenPageLimit(title.length);
        viewpager.setAdapter(viewPagerAdapter);
        viewpager.setCurrentItem(0);
        viewpager.setNoScroll(false);
    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }


    @OnClick({R.id.zuo, R.id.you})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.zuo:
                if(index==0){
                    index=2;
                    viewpager.setCurrentItem(index);
                }else{
                    index=index-1;
                    viewpager.setCurrentItem(index);
                }

                break;
            case R.id.you:
                if(index==2){
                    index=0;
                    viewpager.setCurrentItem(index);
                }else{
                    index=index+1;
                    viewpager.setCurrentItem(index);
                }

                break;
        }
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {

        private List<BaseFragment> fragmentList;

        public ViewPagerAdapter(FragmentManager fm, List<BaseFragment> fragmentList) {
            super(fm);
            this.fragmentList = fragmentList;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return title[position];
        }
    }
}
